Vue.use(VueResource)
new Vue({
    el: '#app',
    data: {
        userInfo: {
            name: '',
            password: ''
        },
        rule: {
            password: /^[\w]{6,16}$/
        }
    },
    methods: {
        login: function() {
            var user = this.userInfo
            if (!user.name) {
                return $$.alert('用户名为空！')
            }
            if (!user.password) {
                return $$.alert('密码为空！')
            }
            if (!this.rule.password.test(user.password)) {
                return $$.alert('密码格式不对！')
            }
            this.$http.get('/user/login', {
                params: this.userInfo
            }).then(function(res) {
                if (res.data.code == 100) {
                    $$.alert('登陆成功！')
                    var user = res.data.data.user
                    $$.localData('memoryClassUser', user)
                    setTimeout(function() {
                        location.href = 'http://' + location.host
                    }, 1000)
                } else {
                    $$.alert(res.data.msg)
                }
            })
        }
    }
})